import math

while True:
    locs=input().strip().split(';')
    locarr=[]
    for loc in locs:
        loc = loc.strip('[').strip(']').split(',')
        loc = list(map(int,loc))
        locarr.append(loc)
    # 获取快递员坐标
    curloc=input().strip().split(',')
    curloc = list(map(int,curloc))
    
    def dist(a,b):
        #计算两点距离
        return math.floor(math.sqrt(math.pow(a[0]-b[0],2)+math.pow(a[1]-b[1],2)))
    
    # 每次都去和我最近的地方
    alldist = []
    res = 0
    
    while locarr:
        for loci in locarr:
            dis=dist(curloc,loci)
            alldist.append(dis)
        #去最近的位置
        ind = alldist.index(min(alldist))
        res += min(alldist)
        #更新当前位置
        curloc=locarr[ind]
        #删除已处理位置
        del locarr[ind]
        alldist = []
        
    print(res)